namespace debounce_throttle {
    function debonuce(func: Function, delay: number): Function {
        let timer: NodeJS.Timeout | null = null;
        return function (this: any) {
            let constext: any = this;
            let args: IArguments = arguments;
            timer ? clearTimeout(timer) : null;
            timer = setTimeout(() => {
                func.apply(constext, args);
            }, delay)
        }
    }
    function s1() {
        console.log('s1');

    }

    debonuce(s1, 1000)()

    // 节流函数

    function throttle(func: Function, limit: number): Function {
        let inThrottle: any;
        return function (this: any) {
            const context: any = this;
            const args: IArguments = arguments;
            if (!inThrottle) {
                func.apply(context, args);
                inThrottle = true;
                setTimeout(() => {
                    inThrottle = false;
                }, limit);
            }
        }
    }

    function s2() {
        console.log('s2');
    }
    throttle(s2, 1000)();
}